package com.wangsh.splider.system.pojo;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wangsh.splider.common.pojo.BasePojo;
 
/**
 * @author Songhy
 */
public class ASysWebUrl extends BasePojo<ASysWebUrl>
{  
	private int id;
	private int websiteId;
	private String name;
	private String url;
	private String header;
	private String request;
	private int  totalCount;
	private int succedCount;
	private int failedCount;
	private int reqtype;
	private String method;
	private int batchSize;
	private int pageSize;
	private int headerNum;
	private String response;
	private String responseHeader;
	private String notifyUrl;
	private String content;
	private byte souType ;
	private byte status;
	private Date createTime;
	private Date updateTime;
	private Date pubTime;

	/* 关联关系 */
	private ASysWebSite webid;
	
	private JSONArray requestArr = new JSONArray();
	private JSONArray headerArr = new JSONArray();

	/*--字符串表示--*/
	private String statusStr;
	private String reqtypeStr;
	private String souTypeStr ;

	/* 存储所有状态的容器 */
	private Map<String,String> enumsMap = new TreeMap<String, String>();

	public Map<String, String> getEnumsMap()
	{
		// 根据状态值获取字符串描述
		ASysWebUrlEnum[] sysWeurlEnums = ASysWebUrlEnum.values();
		for (int i = 0; i < sysWeurlEnums.length; i++)
		{
			ASysWebUrlEnum sysWeurlEnum = sysWeurlEnums[i];
			String key = sysWeurlEnum.toString() ;
			if(key.lastIndexOf("_") != -1)
			{
				key = key.substring(0,key.lastIndexOf("_")) ; 
			}
			enumsMap.put(key + "-" + sysWeurlEnum.getStatus() + "", sysWeurlEnum.getName());
		}
		return enumsMap;
	}
	
	public String getStatusStr()
	{
		// 根据状态值获取字符串描述
		ASysWebUrlEnum[] sysWeurlEnums = ASysWebUrlEnum.values();
		for (int i = 0; i < sysWeurlEnums.length; i++)
		{
			ASysWebUrlEnum sysWeurlEnum = sysWeurlEnums[i];
			if (sysWeurlEnum.toString().startsWith("STATUS_"))
			{
				// 表示是状态的标识
				if (sysWeurlEnum.getStatus() == this.getStatus())
				{
					this.statusStr = sysWeurlEnum.getName();
					break;
				}
			}
		}
		return statusStr;
	}
	
	public String getReqtypeStr()
	{

		// 根据类型值获取字符串描述
		ASysWebUrlEnum[] sysWeurlEnums = ASysWebUrlEnum.values();
		for (int i = 0; i < sysWeurlEnums.length; i++)
		{
			ASysWebUrlEnum sysWeurlEnum = sysWeurlEnums[i];
			if (sysWeurlEnum.toString().startsWith("REQTYPE_"))
			{
				// 表示是类型的标识
				if (sysWeurlEnum.getStatus() == this.getReqtype())
				{
					this.reqtypeStr = sysWeurlEnum.getName();
					break;
				}
			}
		}
		return reqtypeStr;
	}
	
	@Override
	public JSONObject toJSON()
	{
		JSONObject resultJSON =  super.toJSON();
		resultJSON.remove("header");
		return resultJSON ; 
	}

	public String getSouTypeStr()
	{
		// 根据来源类型值获取字符串描述
		ASysWebUrlEnum[] enums = ASysWebUrlEnum.values();
		for (int i = 0; i < enums.length; i++)
		{
			ASysWebUrlEnum enumTemp = enums[i];
			if (enumTemp.toString().startsWith("SOUTYPE_"))
			{
				// 表示是来源类型的标识
				if (enumTemp.getStatus() == this.getSouType())
				{
					this.souTypeStr = enumTemp.getName();
					break;
				}
			}
		}
		return souTypeStr;
	}

	public JSONArray getRequestArr()
	{
		this.requestArr = JSON.parseArray(this.request);
		if (requestArr == null)
		{
			this.requestArr = new JSONArray();
		}
		return requestArr;
	}
	
	public JSONArray getHeaderArr()
	{
		this.headerArr = JSON.parseArray(this.header);
		if (headerArr == null)
		{
			this.headerArr = new JSONArray();
		}
		return headerArr;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getWebsiteId() {
		return websiteId;
	}

	public void setWebsiteId(int websiteId) {
		this.websiteId = websiteId;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getHeader() {
		return header;
	}

	public void setHeader(String header) {
		this.header = header;
	}

	public String getRequest() {
		return request;
	}

	public void setRequest(String request) {
		this.request = request;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public byte getStatus() {
		return status;
	}

	public void setStatus(byte status) {
		this.status = status;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public Date getPubTime() {
		return pubTime;
	}

	public void setPubTime(Date pubTime) {
		this.pubTime = pubTime;
	}

	public ASysWebSite getWebid() {
		return webid;
	}

	public void setWebid(ASysWebSite webid) {
		this.webid = webid;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public String getNotifyUrl() {
		return notifyUrl;
	}

	public void setNotifyUrl(String notifyUrl) {
		this.notifyUrl = notifyUrl;
	}
	public int getSuccedCount() {
		return succedCount;
	}

	public void setSuccedCount(int succedCount) {
		this.succedCount = succedCount;
	}

	public int getFailedCount() {
		return failedCount;
	}

	public void setFailedCount(int failedCount) {
		this.failedCount = failedCount;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public int getHeaderNum() {
		return headerNum;
	}

	public void setHeaderNum(int headerNum) {
		this.headerNum = headerNum;
	}

	public String getResponse() {
		return response;
	}

	public void setResponse(String response) {
		this.response = response;
	}

	public String getResponseHeader() {
		return responseHeader;
	}

	public void setResponseHeader(String responseHeader) {
		this.responseHeader = responseHeader;
	}

	public int getBatchSize() {
		return batchSize;
	}

	public void setBatchSize(int batchSize) {
		this.batchSize = batchSize;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getReqtype() {
		return reqtype;
	}

	public void setReqtype(int reqtype) {
		this.reqtype = reqtype;
	}
	public byte getSouType() {
		return souType;
	}

	public void setSouType(byte souType) {
		this.souType = souType;
	}
}